﻿using Dal;
using IBll;
using IDal;
using Model;

namespace Bll
{
    public class RecipeBll : IRecipeBll
    {
         public RecipeBll(IRecipeDal<Recipe> recip, IRecipeDal<Classification> recipeDa)
        {
            Recip = recip;
            RecipeDa = recipeDa;
        }

        public IRecipeDal<Recipe> Recip { get; }
        public IRecipeDal<Classification> RecipeDa { get; }

        public async Task<int> AddAnync(Recipe recipe)
        {
              return await  Recip.AddAnync(recipe);
        }

        public  dynamic Show(string? name, int classificationId = -1)
        {
            var recipe = Recip.GetAllAnync();
            var classification = RecipeDa.GetAllAnync();
            var linq = from a in classification
                       join b in recipe
                        on a.ClassificationId equals b.ClassificationId
                       select new
                       {
                          b.RecipeName,
                          b.ClassificationId,
                          b.Share,
                          b.Label,                      
                          b.RecipeType,
                          b.RecipeId,
                          b.RecipeImg,
                          a.ClassificationName,
                          b.RecipeDate,
                     
                       };

            if (!string.IsNullOrEmpty(name))
            {
                linq = linq.Where(x => x.RecipeName.Contains(name));

            }
            if (classificationId!=-1)
            {
                linq = linq.Where(x => x.ClassificationId.Equals(classificationId));
            }

             return linq;

        }


    }
}
